<#assign base=request.contextPath />
<!DOCTYPE html>
<html>
<head>
  <base href="${base}">	
  <meta charset="utf-8">
  <title>角色列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="${base}/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="${base}/layuiadmin/style/admin.css" media="all">
  <link rel="stylesheet" href="${base}/css/my.css" media="all">
</head>

<body>
	<div class="layui-fluid">
		<div class="layui-card">
			<!-- 搜索栏 -->
			<div class="layui-form layui-card-header layuiadmin-card-header-auto">
				<div class="layui-form-pane">
					<div class="layui-form-item">
						<label class="layui-form-label" style="width: 88px;">表名</label>
						<div class="layui-input-inline" style="width: 200px;">
							<input type="text" name="Q_LIKES_tableName" class="layui-input" placeholder="表名称" />
						</div>
						<div class="layui-input-inline" style="width: 100px">
							<button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-search">
            					<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 检索
          					</button>            				
						</div>
					</div>
				</div>
			</div>			
			<!-- 表格 -->
			<div class="layui-card-body">
				<div style="padding-bottom:10px">
					<div class="layui-btn-group">
						<button class="layui-btn layui-btn-normal layuiadmin-btn-list" data-type="add"><i class="layui-icon layui-icon-add-1"></i> 添加</button>
						<button class="layui-btn layui-btn-danger layuiadmin-btn-list" data-type="batchdel"><i class="layui-icon layui-icon-close"></i> 删除</button>
					</div>
				</div>
				<table id="LAY-table" lay-filter="LAY-table"></table>
			</div>
		</div>
	</div>

	<!-- 自定义模板 -->
  	<script type="text/html" id="tr-opts">
    	<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
  	</script>
	
  	<script src="${base}/layuiadmin/layui/layui.js"></script>
  	<script>
  	layui.config({
    	base: '${base}/layuiadmin/' //静态资源所在路径
  	}).extend({
    	index: 'lib/index',
    	jwt: '{/}${base}/js/lib/jwt'
  	}).use(['index', 'table', 'jwt'], function(){
    	var table = layui.table,
    		form = layui.form,
    		jwt = layui.jwt;
        	 $ = layui.$;
    	
    	// 创建表格
        table.render({
			elem: '#LAY-table',
			even: true,  //开启隔行背景
			//size: 'sm',  //小尺寸的表格
			height: 'full-180',  //容器高度
			cols: [[
				{checkbox: true},
				{title: '序号', type:'numbers', align: 'center', width: 40},
                {title: '状态', align:'center', field: 'enabled', width: 60, templet: function(d) {
					if(d.enabled == 1) {
						return '<img title="激活" src="${base}/images/flag/customer/effective.png"/>';
					}
					return '<img title="禁用" src="${base}/images/flag/customer/invalid.png"/>';
                }},
				{title: '表名', align:'center', field: 'tableName', minWidth: 120},
				{title: '主键列名', align:'center', field: 'pkName', minWidth: 120},
				{title: "实体名", align:'center', field: 'entityName', minWidth: 120},
				{title: "表中文名", align:'center', field: 'tableNameCn', minWidth: 120},
                {title: '同步方向',align:'center',field: 'rsyncDir',minWidth: 120,templet:function (d) {
					if(d.rsyncDir == 1) {
						return '<div>增量</div>';
					}
					return '<div>全量</div>';
                }},
                {title: '同步方式',align:'center',field: 'rsyncType',  minWidth: 120,templet:function (d) {
					if(d.rsyncType == 1){
						return '<div>同步到移动端</div>';
					}
					// else if(d.rsyncType == 2){
					// 	return '<div>同步到服务器端</div>';
					// }
					return '<div>先同步到移动端再同步到服务器端</div>';
				}},
                {title: '表类型',align:'center', field: 'basic', minWidth: 120, templet:function (d) {
					if(d.basic == 0) {
						return '<div>基础表</div>';
					}
					return '<div>业务表</div>';
				}},
                {title: '管理', fixed: 'right', width: 210, align: 'center', toolbar: '#tr-opts'}
			]],
			url: '${base}/comm/rsynctable/list',
			headers: {
				'Authorization': jwt.getCookie('token')
			},
			page: true, 
			limits: [15, 30, 50, 100, 200], 
			limit: 15,  //默认采用25
			loading: true, 
			done: function (res, curr, count) {}
		});
    	
     	// 工具栏
        table.on('tool(LAY-table)', function(obj) {
            var data = obj.data;
            console.log(data)
            if(obj.event === 'del') {
                layer.confirm('您确定要删除行吗？', function(index) {
                    jwt.ajax({
                        url: '${base}/comm/rsynctable/multiDel',
                        data: {
                            ids: data.oid
                        },
                        success: function(json) {
                            table.reload('LAY-table');
                            layer.msg(json.msg);
                        }
                    });
                })
            } else if(obj.event === 'edit') {
                layer.open({
                    type: 2,
                    title: '数据同步-详情',
                    content: '${base}/comm/rsynctable/html/edit?oid=' + data.oid,
                    maxmin: true,
                    area: ['800px', '400px'],
                    btn: ['确定', '取消'],
                    yes: function(index, layero){
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#LAY-form-submit");
                        submit.click();
                    }
                });
            }
        });
    
    	//监听搜索
    	form.on('submit(LAY-search)', function(data) {
      		var field = data.field;      
      		//执行重载
      		table.reload('LAY-table', {
        		where: field,
        		page: {curr: 1}
      		});
    	});    	
    
    	var $ = layui.$, active = {
            batchdel: function() {
                var checkStatus = table.checkStatus('LAY-table'),
                    checkData = checkStatus.data; //得到选中的数据

                if(checkData.length === 0) {
                    layer.msg('请选择数据');
                    return false;
                }

                var idArr = [];
                for(var i=0; i<checkData.length; i++) {
                    idArr.push(checkData[i].oid);
                }
                layer.confirm('确定删除吗？', function(index) {
                    jwt.ajax({
                        url: '${base}/comm/rsynctable/multiDel',
                        data: {
                            ids: idArr.join(',')
                        },
                        success: function(json) {
                            table.reload('LAY-table');
                            layer.msg(json.msg);
                        }
                    });
                });
            },
            add: function() {
                layer.open({
                    type: 2,
                    title: '数据同步-详情',
                    content: '${base}/comm/rsynctable/html/add',
                    maxmin: true,
                    area: ['800px', '400px'],
                    btn: ['确定', '取消'],
                    yes: function(index, layero){
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#LAY-form-submit");
                        submit.click();
                    }
                });
            }
   		}; 

		$('.layui-btn.layuiadmin-btn-list').on('click', function(){
      		var type = $(this).data('type');
      		active[type] ? active[type].call(this) : '';
		});

  	});
  </script>
</body>
</html>
